<template>
    <div style="height:100%">
      <div>
        <div class='content-title'>
          <div class='content-title-parent'>失物管理</div>
          /
          <div class='content-title-child'>失物招领</div>
        </div>
        <hr class='content-hr'/>
      </div>
      <!--表格筛选条件-->
      <el-row style="margin-top:10px" class='lostManaClass'>
        <el-form v-model="filterForm" ref="filterForm" :inline="true">
          <el-form-item label="物品关键字：" label-width="100px">
            <el-input style="width:160px" v-model="filterForm.materialName"></el-input>
          </el-form-item>
          <el-form-item label="物品分类：">
            <el-select style="width:160px" v-model="filterForm.classId" placeholder="选择物品分类" @change="changeCategory('filterForm')">
              <el-option
                v-for="item in categoryList"
                :key="item.classId"
                :label="item.className"
                :value="item.classId">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="遗失地点：">
              <el-cascader
                style="width:160px"
                v-model="filterForm.airportList"
                expand-trigger="hover"
                :options="filterForm.airportNameList"
                @change="selectAirport('filterForm')"
                :props="airportProps"
              >
              </el-cascader>
          </el-form-item>
          <el-form-item label="乘坐航班号：" >
            <el-input style="width:160px" v-model="filterForm.flightNumber"></el-input>
          </el-form-item>
          <el-form-item label="登记日期：" label-width="100px">
            <el-date-picker
              v-model="filterForm.lostTime"
              type="daterange"
              align="right"
              unlink-panels
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :picker-options="pickerOptions">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="物品状态：" >
            <el-checkbox-group v-model="filterForm.goodsState">
              <el-checkbox label="待领取"></el-checkbox>
              <el-checkbox label="已领取"></el-checkbox>
            </el-checkbox-group>
          </el-form-item>
          <el-form-item label="" >
            <el-button type="primary" style="background-color:#2280E9;border-color:#2280E9;width:60px;" @click="getLostManaListFro()">查询</el-button>
          </el-form-item>
          <el-form-item label="" style="float:right;margin-right:20px">
            <el-button type="warning" style="width:80px;" @click="addVisable = true">添加失物</el-button>
          </el-form-item>
        </el-form>
      </el-row>
      <!--查询表格数据-->
      <el-row>
        <!-- <el-table 
          v-loading="loading"
          :element-loading-text="loadingText"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(1, 1, 1, 0.8)"
          :data="filterFormFro.tableData"
          :border="true"
          :row-class-name="tableRowClassName"
          :header-cell-class-name = "tableHeaderClassName"
          v-bind:style="{width: tableWidth + 'px'}">
            <el-table-column prop="index" label="序号"  width="150">
            </el-table-column>
            <el-table-column prop="materialName" label="物品名称"  width="150">
            </el-table-column>
            <el-table-column prop="className" label="物品分类" width="150">
            </el-table-column>
            <el-table-column prop="codeAirport" label="所属机场" width="150">
            </el-table-column>
            <el-table-column prop="terminalName" label="遗失地点" width="100">
            </el-table-column>
            <el-table-column prop="address" label="详细地址" min-width="200">
            </el-table-column>
            <el-table-column prop="registerTime" label="登记日期" width="150">
            </el-table-column>
            <el-table-column prop="goodsState" label="状态" width="150">
            </el-table-column>
            <el-table-column label="操作" width="200" fixed="right">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="danger"
                @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
              <el-button
                size="mini"
                type="danger"
                @click="handleDelete(scope.$index, scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table> -->
        <el-table
      :data="tableData"
      border
      style="width: 400px">
      <el-table-column
        fixed
        prop="date"
        label="日期"
        width="150">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="120">
      </el-table-column>
      <el-table-column
        prop="province"
        label="省份"
        width="120">
      </el-table-column>
      <el-table-column
        prop="city"
        label="市区"
        width="120">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址"
        width="300">
      </el-table-column>
      <el-table-column
        prop="zip"
        label="邮编"
        width="120">
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        width="100">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
          <el-button type="text" size="small">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
      </el-row>
      <!--分页-->
      <el-row>
        <div class="pagination" style="text-align:center" v-show="paginationVisible">
          <el-pagination
            @current-change="handleCurrentChange"
            background
            :current-page="filterForm.pageNum"
            :page-size="20"
            layout="total, prev, pager, next"
            :page-count="filterFormFro.totalPage">
          </el-pagination>
        </div>
      </el-row>              
      <!-- 添加失物信息信息弹窗 -->
      <el-dialog title="添加失物:"   :visible.sync="addVisable"
          :closeOnClickModal="false" 
          width="550px"
          class="categoryManaDialog"
          :close-on-click-modal="false" 
          :close-on-press-escape="false"
          @close="resetForm('addForm')">
        <el-form :model='addForm' ref="addForm" :rules="addRules" label-width="155px">
            <el-form-item label="物品名称："  prop="materialName">
              <el-input style='width:240px' v-model="addForm.materialName"></el-input>
            </el-form-item>
            <el-form-item label="物品分类："  prop="classId">
              <el-select style='width:240px' v-model="addForm.classId" clearable placeholder="选择物品分类" @change="changeCategory('addForm')">
                <el-option
                  v-for="item in categoryList"
                  :key="item.classId"
                  :label="item.className"
                  :value="item.classId">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="遗失地点：" prop="airportList">
              <el-cascader
                style='width:240px'
                v-model="addForm.airportList"
                expand-trigger="hover"
                :options="addForm.airportNameList"
                @change="selectAirport('addForm')"
                :props="airportProps"
              >
              </el-cascader>
            </el-form-item>
            <el-form-item label="详细地址："  prop="address">
              <el-input style='width:240px' v-model="addForm.address" ></el-input>
            </el-form-item>
            <el-form-item label="登记时间："  prop="registerTime">
                <el-date-picker
                  style='width:240px'
                  clearable
                  v-model="addForm.registerTime"
                  type="datetime"
                  placeholder="选择日期">
                </el-date-picker>
            </el-form-item>
            <el-form-item label="领取地点：" prop="pickairportList">
              <el-cascader
                clearable
                style='width:240px'
                v-model="addForm2.airportList"
                expand-trigger="hover"
                :options="addForm2.airportNameList"
                @change="selectAirport('addForm2')"
                :props="airportProps"
              >
              </el-cascader>
            </el-form-item>
            <el-form-item label="物品状态："  prop="goodsState">
              <el-checkbox-group style='width:240px' v-model="addForm.goodsState">
                <el-checkbox label="待领取"></el-checkbox>
                <el-checkbox label="已领取"></el-checkbox>
              </el-checkbox-group>
            </el-form-item>
            <el-form-item label="" >
              <el-button type="primary" style="width:240px" @click="submitAdd()">保 存</el-button>
            </el-form-item>
        </el-form>
      </el-dialog>
      <!-- 编辑失物信息信息弹窗 -->
      <el-dialog title="编辑失物信息:"   :visible.sync="editVisable"
          :closeOnClickModal="false" 
          width="550px"
          class="categoryManaDialog"
          :close-on-click-modal="false" 
          :close-on-press-escape="false"
          @close="resetForm('editForm')">
        <el-form :model='editForm' ref="editForm" label-width="165px">
            <el-form-item label="物品名称：" prop="materialName">
              <el-input style='width:240px' v-model="editForm.materialName"></el-input>
            </el-form-item>
            <el-form-item label="物品分类："  prop="unActIncome">
              <el-select style='width:240px' v-model="editForm.classId" placeholder="选择物品分类" @change="changeCategory('addForm')">
                <el-option
                  v-for="item in categoryList"
                  :key="item.classId"
                  :label="item.className"
                  :value="item.classId">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="遗失地点：" prop="airportList">
              <el-cascader
                style='width:240px'
                v-model="editForm.airportList"
                expand-trigger="hover"
                :options="editForm.airportNameList"
                @change="selectAirport('editForm')"
                :props="airportProps"
              >
              </el-cascader>
            </el-form-item>
            <el-form-item label="详细地址：" prop="address">
              <el-input style='width:240px' v-model="editForm.address"></el-input>
            </el-form-item>
            <el-form-item label="登记时间："  prop="registerTime">
                <el-date-picker
                  style='width:240px'
                  v-model="editForm.registerTime"
                  type="datetime"
                  placeholder="选择日期">
                </el-date-picker>
            </el-form-item>
            <el-form-item label="领取地点："  prop="airportList">
              <el-cascader
                style='width:240px'
                v-model="editForm2.airportList"
                expand-trigger="hover"
                :options="editForm.airportNameList"
                @change="selectAirport('editForm2')"
                :props="airportProps"
              >
              </el-cascader>
            </el-form-item>
            <el-form-item label="物品状态："  prop="goodsState">
              <el-checkbox-group style='width:240px' v-model="editForm.goodsState">
                <el-checkbox label="待领取"></el-checkbox>
                <el-checkbox label="已领取"></el-checkbox>
              </el-checkbox-group>
            </el-form-item>
            <el-form-item label="" >
              <el-button type="primary" style="width:240px" @click="submitEdit()">保 存</el-button>
            </el-form-item>
        </el-form>
      </el-dialog>
    </div>
</template>
<script>
import apiBus from '../../api/businessPlat/apiBus.js'
import '../../../static/css/businessPlat/common.css'
import '../../../static/css/businessPlat/lostMana.css'
export default {
  created () {
    this.init()
    // this.getAllClassFro()
    // this.getAllTerminalFro()
    // this.getLostManaListFro()
  },
  data () {
    var checkGetAirport = (rule, value, callback) => { // 添加失物领取地点验证
      console.log('验证')
      console.log(this.addForm2.airportList)
      if (this.addForm2.airportList.length > 0) {
        callback()
      } else {
        callback(new Error('请选择领取地点'))
      }
    }
    return {
      tableData: [{
        date: '2016-05-03',
        name: '王小虎',
        province: '上海',
        city: '普陀区',
        address: '上海市普陀区金沙江路 1518 弄',
        zip: 200333
      }, {
        date: '2016-05-02',
        name: '王小虎',
        province: '上海',
        city: '普陀区',
        address: '上海市普陀区金沙江路 1518 弄',
        zip: 200333
      }, {
        date: '2016-05-04',
        name: '王小虎',
        province: '上海',
        city: '普陀区',
        address: '上海市普陀区金沙江路 1518 弄',
        zip: 200333
      }, {
        date: '2016-05-01',
        name: '王小虎',
        province: '上海',
        city: '普陀区',
        address: '上海市普陀区金沙江路 1518 弄',
        zip: 200333
      }],
      addVisable: false, // 添加失物弹窗
      baseFeeVisable: true,
      loading: false, // 加载是否显示
      loadingText: '', // 加载显示内容
      categoryList: [], // 下拉框中的分类列表
      tableWidth: '', // 表格宽度
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick (picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近一个月',
          onClick (picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近三个月',
          onClick (picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
            picker.$emit('pick', [start, end])
          }
        }]
      },
      airportProps: {
        value: 'label',
        children: 'terminals'
      },
      props: {
        value: 'label',
        children: 'cities'
      },
      filterFormFro: { // 查询获得列表
        tableData: [],
        totalPage: 0
      },
      filterForm: { // 筛选表单
        materialName: '', // 失物名称
        className: '',
        classId: '',
        terminalId: [],
        terminalName: [],
        airportName: '',
        airportId: '',
        flightNumber: '',
        lostTime: [],
        pageNum: 1,
        isDelete: '',
        airportNameList: [],
        airportList: [],
        goodsState: [], // 物品状态
        statusList: ['未找到', '已找到']
      },
      testAirport: [
        {
          airportName: '机场1',
          airportId: '机场1',
          terminalName: '航站楼11',
          terminalId: '航站楼ID'
        },
        {
          airportName: '机场2',
          airportId: '机场ID',
          terminalName: '航站楼21',
          terminalId: '航站楼ID'
        },
        {
          airportName: '机场1',
          airportId: '机场1',
          terminalName: '航站楼12',
          terminalId: '航站楼ID'
        }
      ],
      paginationVisible: false, // 表格下方分页是否显示
      noteVisible: false,
      formLabelWidth: '30%',
      addForm: {
        airportNameList: [],
        materialName: '',
        classId: '',
        airportList: [],
        terminalId: [],
        terminalName: [],
        airportId: '',
        airportName: '',
        address: '',
        registerTime: '',
        goodsState: []
      },
      addForm2: {
        airportNameList: [],
        airportList: [],
        airportId: '',
        airportName: '',
        terminalId: [],
        terminalName: []
      },
      editForm: {
        index: 0,
        airportNameList: [],
        materialName: '',
        classId: '',
        airportList: [],
        terminalId: [],
        terminalName: [],
        airportId: '',
        airportName: '',
        address: '',
        registerTime: '',
        goodsState: []
      },
      editForm2: {
        airportNameList: [],
        airportList: [],
        airportId: '',
        airportName: '',
        terminalId: [],
        terminalName: []
      },
      editVisable: false,
      deleteForm: { // 删除表单
        index: '',
        materialId: ''
      },
      addRules: { // 弹窗添加标签信息验证规则
        materialName: [
          { required: true, message: '请填写物品名称', trigger: 'blur' },
          { max: 20, message: '物品名称最多20个字', trigger: 'blur' }
        ],
        classId: [
          { required: true, message: '请选择所属分类', trigger: 'change' }
        ],
        airportList: [
          { required: true, message: '请选择遗失地点', trigger: 'change' }
        ],
        address: [
          { required: true, message: '请填写详细地址', trigger: 'blur' },
          { max: 30, message: '详细地址最多30个字', trigger: 'blur' }
        ],
        registerTime: [
          { required: true, message: '请填写遗失时间', trigger: 'blur' }
        ],
        pickairportList: [
          { validator: checkGetAirport, trigger: 'change' }
        ],
        goodsState: [
          { required: true, message: '请选择物品状态', trigger: 'change' }
        ]
      }
    }
  },
  methods: {
    /** 页面处理，数据格式处理函数 */
    // 分页页面跳转时
    handleCurrentChange (val) {
      this.filterForm.pageNum = val
      //  console.log(`当前页: ${val}`)
    },
    // 处理后台发来的数据以显示在下拉框中（主要针对机场和航站楼，使其可以二级联动选择）
    setDropdown (testAirport, form) {
      let parentIdList = []
      let totalList = []
      for (let i = 0; i < testAirport.length; i++) {
        if (parentIdList.indexOf(testAirport[i].airportId) === -1) {
          parentIdList.push(testAirport[i].airportId)
          totalList.push({
            label: testAirport[i].airportName,
            airportId: testAirport[i].airportId,
            terminals: []
          })
        }
      }
      for (let i = 0; i < totalList.length; i++) {
        testAirport.forEach((item) => {
          if (item.airportId === totalList[i].airportId) {
            totalList[i].terminals.push({
              label: item.terminalName,
              terminalId: item.terminalId
            })
          }
        })
      }
      if (form === 'filterForm') {
        for (let i = 0; i < totalList.length; i++) {
          totalList[i].terminals.push({
            label: '全部',
            terminalId: ''
          })
        }
      }
      console.log('setDropdown')
      this[form].airportNameList = totalList
      console.log(this[form].airportNameList)
    },
    // 将时间从时间戳转化为字符串显示
    formatDateFro (now) {
      var year = now.getFullYear()
      var month = now.getMonth() + 1
      month = month < 10 ? '0' + month : month
      var date = now.getDate()
      date = date < 10 ? ('0' + date) : date
      var hour = now.getHours()
      hour = hour < 10 ? ('0' + hour) : hour
      var minute = now.getMinutes()
      minute = minute < 10 ? ('0' + minute) : minute
      var second = now.getSeconds()
      second = second < 10 ? ('0' + second) : second
      return year + '-' + month + '-' + date + ' ' + hour + ':' + minute + ':' + second
    },
    // 下拉框选择机场及航站楼
    selectAirport (Form) {
      for (let i = 0; i < this[Form].airportNameList.length; i++) {
        this[Form].terminalId = []
        if (this[Form].airportNameList[i].label === this[Form].airportList[0]) {
          this[Form].airportId = this[Form].airportNameList[i].airportId
          this[Form].airportName = this[Form].airportNameList[i].label
          for (let m = 0; m < this[Form].airportNameList[i].terminals.length; m++) {
            if (this[Form].airportList[1] === this[Form].airportNameList[i].terminals[m].label && this[Form].airportList[1] !== '全部') {
              this[Form].terminalId.push(this[Form].airportNameList[i].terminals[m].terminalId)
              this[Form].terminalName.push(this[Form].airportNameList[i].terminals[m].label)
              break
            } else if (this[Form].airportList[1] === '全部') {
              if (this[Form].airportNameList[i].terminals[m].label !== '全部') {
                this[Form].terminalId.push(this[Form].airportNameList[i].terminals[m].terminalId)
                this[Form].terminalName.push(this[Form].airportNameList[i].terminals[m].label)
              }
            }
          }
          break
        }
      }
    },
    setDetailFro () {
      this.editVisable = false
      this.$message.success('失物详情编辑成功')
    },
    // 增加标签，点击“保存”
    submitAdd () {
      this.$refs['addForm'].validate((valid) => {
        if (valid) {
          this.addLostManaFro()
        } else {
          return false
        }
      })
    },
    // 编辑标签，点击“保存”
    submitEdit () {
      this.$refs['editForm'].validate((valid) => {
        if (valid) {
          this.editLostManaFro()
        } else {
          return false
        }
      })
    },
    // 重置表单
    resetForm (formName) {
      this.$nextTick(function () {
        this.$refs[formName].resetFields()
      })
    },
    // 初始化搜索数据
    init () {
      let end = new Date()
      let start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
      this.filterForm.lostTime[0] = start
      this.filterForm.lostTime[1] = end
    },
    // 改变分类选择
    changeCategory (Form) {
      console.log('changeCategory')
    },
    tableHeaderClassName ({row, column, rowIndex, columnIndex}) {
      if (rowIndex === 0) {
        return 'headerClass'
      }
    },
    tableRowClassName ({row, rowIndex}) {
      return 'rowClass'
    },
    // 点击表格中的编辑按钮
    handleEdit (index, row) {
      console.log(row)
      let data = this.filterFormFro.tableData[index]
      this.editForm.materialName = data.materialName
      this.editForm.materialId = data.materialId
      this.editForm.className = data.className
      this.editForm.airportName = data.airportName
      this.editForm.terminalName[0] = data.terminalName
      this.editForm.airportList[0] = data.airportName
      this.editForm.airportList[1] = data.terminalName
      this.editForm.address = data.address
      this.editForm.registerTime = data.registerTime
      this.editForm.goodsState[0] = data.goodsState
      this.editForm2.airportList[0] = data.pickUpAirportName
      this.editForm2.airportList[1] = data.pickUpTerminalName
      this.editForm2.pickUpTerminalName = data.pickUpTerminalName
      this.editForm2.pickUpAirportName = data.pickUpAirportName
      this.editVisable = true
    },
    // 点击表格中的删除按钮
    handleDelete (index, row) {
      let data = this.filterFormFro.tableData[index]
      this.deleteForm.materialId = data.materialId
      this.$confirm('确认删除该失物吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deleteLostManaFro()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    cancleEdit (formName) {
      this.resetError(formName)
      this.editVisable = false
    },
    // 重置表单
    resetError (formName) {
      this.$nextTick(function () {
        this.$refs[formName].resetFields()
      })
    },
    setDeleteFro () {
      this.noteVisible = false
      this.$message.success('优惠券<' + this.deleteForm.couponName + '>已删除')
    },
    // 从后台查询所有航站楼
    getAllTerminalFro () {
      console.log('getAllTerminalFro')
      let para = {
        header: JSON.stringify({
          token: '',
          beanId: 'airportService_v1'
        }),
        body: JSON.stringify({})
      }
      console.log(para)
      apiBus.getAllTerminal(para).then(res => {
        console.log('getAllTerminalFro回参')
        console.log(res)
        let terminalList = []
        if (res.data.body.result === 1000) {
          terminalList = res.data.body.content.list
          this.setDropdown(terminalList, 'filterForm')
          this.setDropdown(terminalList, 'addForm')
          this.setDropdown(terminalList, 'editForm')
          this.setDropdown(terminalList, 'addForm2')
          this.setDropdown(terminalList, 'editForm2')
        } else {
          this.$message.error(res.data.body.resultDesp)
        }
      })
      .catch(error => {
        this.$message.error(error)
      })
    },
    // 查询电商标签管理处的电商分类下拉菜单的显示接口
    getAllClassFro () {
      console.log('getAllClassFro')
      let para = {
        header: JSON.stringify({
          token: '',
          beanId: 'businessManageService_v1'
        }),
        body: JSON.stringify({})
      }
      console.log(para)
      apiBus.getAllClass(para).then(res => {
        console.log('getAllClassFro')
        console.log(res)
        this.categoryList = []
        if (res.data.body.result === 1000) {
          this.categoryList = res.data.body.content.list
        } else {
          this.$message.error(res.data.body.resultDesp)
        }
      })
      .catch(error => {
        this.$message.error(error)
      })
    },
    /** 向后台发送删除失物信息 */
    deleteLostManaFro () {
      console.log('deleteLostManaFro')
      let para = {
        header: JSON.stringify({
          token: '',
          beanId: 'lostMeterialService_v1'
        }),
        body: JSON.stringify({
          materialId: this.deleteForm.materialId
        })
      }
      console.log(para)
      apiBus.deleteLostMana(para).then(res => {
        console.log('deleteLostManaFro回参')
        console.log(res)
        if (res.data.body.result === 1000) {
          this.$message.success('成功删除失物信息！')
          this.editVisable = false
          this.getLostManaListFro()
        } else {
          this.$message.error(res.data.body.resultDesp)
        }
      })
      .catch(error => {
        console.log('失败')
        this.$message.error(error)
      })
    },
    /** 向后台发送编辑失物信息 */
    editLostManaFro () {
      console.log('editLostManaFro')
      let terminalId = ''
      let pickUpTerminalId = ''
      let registerTime = ''
      this.editForm.registerTime ? registerTime = this.formatDateFro(new Date(this.editForm.registerTime)) : ''
      this.editForm.terminalId.length > 1 ? terminalId = '' : terminalId = parseInt(this.editForm.terminalId[0])
      this.editForm2.terminalId.length > 1 ? pickUpTerminalId = '' : pickUpTerminalId = parseInt(this.editForm2.terminalId[0])
      terminalId = 1
      let para = {
        header: JSON.stringify({
          token: '',
          beanId: 'lostMeterialService_v1'
        }),
        body: JSON.stringify({
          materialName: this.editForm.materialName,
          classId: parseInt(this.editForm.classId),
          // airportId: parseInt(this.editForm.airportId),
          airportId: 1,
          materialId: parseInt(this.editForm.materialId),
          terminalId: terminalId,
          address: this.editForm.address,
          pickUpTerminalId: pickUpTerminalId,
          pickUpAirportId: parseInt(this.editForm2.airportId),
          registerTime: registerTime,
          receiveState: this.editForm.goodsState[0]
        })
      }
      console.log('ssssssssssssss')
      console.log(this.editForm.materialId)
      console.log(para)
      apiBus.editLostMana(para).then(res => {
        console.log('editLostManaFro回参：')
        console.log(res)
        if (res.data.body.result === 1000) {
          this.$message.success('成功编辑失物信息！')
          this.editVisable = false
          this.getLostManaListFro()
        } else {
          this.$message.error(res.data.body.resultDesp)
        }
      })
      .catch(error => {
        console.log('失败')
        this.$message.error(error)
      })
    },
    /** 向后台发送增加失物信息 */
    addLostManaFro () {
      console.log('addLostManaFro')
      let terminalId = ''
      let pickUpTerminalId = ''
      let registerTime = ''
      this.addForm.registerTime ? registerTime = this.formatDateFro(this.addForm.registerTime) : ''
      this.addForm.terminalId.length > 1 ? terminalId = '' : terminalId = parseInt(this.addForm.terminalId[0])
      this.addForm2.terminalId.length > 1 ? pickUpTerminalId = '' : pickUpTerminalId = parseInt(this.addForm2.terminalId[0])
      terminalId = 1
      let para = {
        header: JSON.stringify({
          token: '',
          beanId: 'lostMeterialService_v1'
        }),
        body: JSON.stringify({
          materialName: this.addForm.materialName,
          classId: parseInt(this.addForm.classId),
          // airportId: parseInt(this.addForm.airportId),
          airportId: 1,
          terminalId: terminalId,
          address: this.addForm.address,
          pickUpTerminalId: pickUpTerminalId,
          pickUpAirportId: parseInt(this.addForm2.airportId),
          registerTime: registerTime,
          receiveState: this.addForm.goodsState[0]
        })
      }
      console.log(para)
      apiBus.addLostMana(para).then(res => {
        console.log('addLostManaFro回参：')
        console.log(res)
        if (res.data.body.result === 1000) {
          this.$message.success('成功添加失物信息！')
          this.addVisable = false
          this.getLostManaListFro()
        } else {
          this.$message.error(res.data.body.resultDesp)
        }
      })
      .catch(error => {
        console.log('失败')
        this.$message.error(error)
      })
    },
    /** 向后台发送请求失物列表接口 */
    getLostManaListFro () {
      this.loading = true
      this.loadingText = '正在拼命加载，请稍等...'
      console.log('getLostManaListFro')
      let terminalId = ''
      let endTime = null
      let startTime = null
      let goodsState = ''
      if (this.filterForm.lostTime && this.filterForm.lostTime.length > 0) {
        endTime = this.formatDateFro(this.filterForm.lostTime[0])
        startTime = this.formatDateFro(this.filterForm.lostTime[1])
      }
      this.filterForm.terminalId.length > 1 ? terminalId = '' : terminalId = parseInt(this.filterForm.terminalId[0])
      this.filterForm.goodsState.length > 0 ? goodsState = this.filterForm.goodsState : goodsState = null
      let para = {
        header: JSON.stringify({
          token: '',
          beanId: 'lostMeterialService_v1'
        }),
        body: JSON.stringify({
          materialName: this.filterForm.materialName,
          classId: parseInt(this.filterForm.classId),
          airportId: parseInt(this.filterForm.airportId),
          terminalId: terminalId,
          startTime: startTime,
          endTime: endTime,
          pageNum: parseInt(this.filterForm.pageNum),
          receiveStates: goodsState
        })
      }
      console.log(para)
      apiBus.getLostReportList(para).then(res => {
        console.log('getLostReportList回参')
        console.log(res)
        this.loading = false
        if (res.data.body.result === 1000) {
          if (res.data.body.content.list.length > 0) {
            this.$message.success('成功提取失物管理信息！')
            let resData = res.data.body.content.list
            this.filterFormFro.tableData = resData
            for (let i = 0; i < resData.length; i++) {
              this.filterFormFro.tableData[i].index = (parseInt(this.filterForm.pageNum) - 1) * 20 + i + 1
              this.filterFormFro.tableData[i].goodsState = resData[i].receiveState
              this.filterFormFro.tableData[i].registerTime = this.formatDateFro(new Date(this.filterFormFro.tableData[i].registerTime))
              if (this.filterFormFro.tableData[i].figureThree) {
                this.filterFormFro.tableData[i].codeAirport = resData[i].figureThree + ' ' + resData[i].airportName
              } else {
                this.filterFormFro.tableData[i].codeAirport = resData[i].tetradCode + ' ' + resData[i].airportName
              }
            }
            this.filterFormFro.totalPage = res.data.body.content.allPages
            this.filterFormFro.totalPage > 1 ? this.paginationVisible = true : this.paginationVisible = false
          } else {
            this.$message.warning('没有相关失物信息')
            this.paginationVisible = false
          }
        } else {
          this.$message.error(res.data.body.resultDesp)
          this.paginationVisible = false
        }
      })
      .catch(error => {
        console.log('失败')
        this.$message.error(error)
      })
    }
  },
  mounted () {
    this.tableWidth = document.body.scrollWidth - 259 - 20
  }
}
</script>